package com.fish.gaiety.gateway.controller;

import com.fish.gaiety.gateway.util.BaseResponseCode;
import com.fish.gaiety.gateway.base.ResponseApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

@RestController
@RequestMapping("/hello")
@Slf4j
public class BaseController {

    @GetMapping()
    public ResponseEntity<String> hello(){
        return
                ResponseEntity.status(HttpStatus.ACCEPTED).body("Hello world!");

    }

    @GetMapping("/2")
    public ResponseEntity<ResponseApi<String>> hello2(){
        return ResponseEntity
                .status(HttpStatus.ACCEPTED)
                .body(ResponseApi.
                        status(BaseResponseCode.BASE_SUCCEED)
                        .body("Hello world!"));
    }

    @PostMapping("/3")
    public void testAsync(){
        log.info("start async");
        CompletableFuture.supplyAsync(()-> {
            try {
                Thread.sleep(5000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.info("throw new exception");
            throw new RuntimeException("Exception");
        });
        log.info("end async");
    }
}
